package chatClient;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class ConnectStage extends Stage{
	
	Group root = new Group();
	Scene scene = new Scene(root, 300, 200);
	Label lbIP = new Label("服务器IP");
	Label lbName = new Label("用户名");
	TextField tfIP = new TextField();
	TextField tfName = new TextField();
	ChatClient client;
	
	public ConnectStage(ChatClient client){
		
		this.client = client;
		
		Button btnConnect = new Button("连接");
		btnConnect.setOnAction(new EventHandler<ActionEvent>() {
			
			@Override
			public void handle(ActionEvent arg0) {
				if(!tfIP.getText().equals("") && !tfName.equals("")){
					client.serverIP = tfIP.getText();
					client.name = tfName.getText();
					client.connectAction();
					ConnectStage.this.close();
				}
			}
		});
		root.getChildren().addAll(lbIP,lbName,tfIP,tfName,btnConnect);
		lbIP.setLayoutX(50);lbIP.setLayoutY(50);
		tfIP.setLayoutX(100);tfIP.setLayoutY(50);
		lbName.setLayoutX(50);lbName.setLayoutY(100);
		tfName.setLayoutX(100);tfName.setLayoutY(100);
		btnConnect.setLayoutX(200);btnConnect.setLayoutY(150);
		this.setScene(scene);
		this.setTitle("连接");
	}
	
}
